package org.example.springboot.service;

import org.example.springboot.entity.User;
import org.example.springboot.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;


    public List<User> getUsersByPage(int pageNum, int pageSize,String username) {
        int offset = (pageNum - 1) * pageSize;
        return userMapper.getUsersByPage(pageSize,offset, username);
    }

    public int getUserCount(String username) {
        return userMapper.getUserCount(username);
    }

    @Transactional
    public void deleteUserByAccount(String account) {
        userMapper.deleteUserByAccount(account);
    }

    @Transactional
    public void insertUser(User user) {
        userMapper.insertUser(user);
    }

    public User getUserByAccount(String account) {
        return userMapper.selectByAccount(account);
    }

    @Transactional
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Transactional
    public void updatePassword(String account, String password) {
        userMapper.updatePassword(account, password);
    }
}
